import { request } from "@yaf/request";
import { toApi } from "@/service/proxyApi";
import { RequestDataType, RespDataType } from "./apiType";

export * from "./apiType";

const { get, postJSON, del, put } = request;

/**
 * 获取字典类型分页列表
 */
export const getDictPageList = (params: { page: number, pageSize: number, dictName?: string, dictType?: string }) => {
  return get<RespDataType.DictPageList>(toApi("api/v1/system/dict/type/list"), params);
}

/**
 * 创建字典
 */
export const createDict = (params: RequestDataType.CreateDictItem) => {
  return postJSON(toApi("api/v1/system/dict/type/add"), params);
}

/**
 * 获取字典类型
 */
export const getDictInfo = (dictId: number) => {
  return get<RespDataType.DictInfoResp>(toApi("api/v1/system/dict/type/get"), { dictId });
}

/**
 * 更新字典类型
 */
export const updateDict = (dictId: number, params: Partial<RequestDataType.UpdateDictItem>) => {
  return put(toApi(`api/v1/system/dict/type/edit`), { dictId, ...params });
}

/**
 * 删除字典类型
 */
export const deleteDict = (dictIds: number[]) => {
  return del(toApi(`api/v1/system/dict/type/delete`), { dictIds });
}

